package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.*;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentSocialActivityRepository extends JpaRepository<StudentSocialActivity, Integer> {

    @Query(value = "select max(StudentSocialActivityId) from StudentSocialActivity  ")
    Integer getMaxId();

    @Query(value = "from StudentSocialActivity where   socialActivity.socialActivityId = ?1 ")
    List<StudentSocialActivity> findByStudentSocialActivity(Integer studentSocialActivityId);

    @Query(value = "from StudentSocialActivity where socialActivity.socialActivityName like %?1% and socialActivity.socialActivityTime like %?2%")
    List<StudentSocialActivity> findBySocialActivityNameTime( String socialActivityName,String  socialActivityTime);


    @Query(value = "from StudentSocialActivity where student.person.num like %?1% and (?2 = '' or socialActivity.socialActivityName like %?2%)")
    List<StudentSocialActivity> findByStudentPersonNumAndSocialActivityName(String studentName, String socialActivityName);

    void deleteByStudentAndSocialActivity(Student student, SocialActivity socialActivity);
}
